import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_oa/route/routes.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class CustomerDetail extends StatefulWidget {
  @override
  _CustomerDetailState createState() => _CustomerDetailState();
}

class _CustomerDetailState extends State<CustomerDetail> {
  List<Map<String, dynamic>> maps = new List();
  List<Widget> items = new List();

  _doWidgets() {
    setMaps();
    List<Widget> listTitles = new List();
    for (var i = 0; i < maps.length; i++) {
      listTitles.add(buildListItem(context, maps[i]));
      if (i == 1) {
        listTitles.add(SizedBox(
          height: 10,
        ));
      }
    }
    return listTitles;
  }

  setMaps() {
    var title = [
      '建档人: ',
      '建档时间: ',
      '目前状态: ',
      '所属类别: ',
      '客户需求: ',
      '客户来源: ',
      '客户姓名: ',
      '客户电话1: ',
      '客户电话2: ',
      '建档人: ',
      '建档时间: ',
      '目前状态: ',
      '所属类别: ',
      '客户需求: ',
      '客户来源: ',
      '客户姓名: ',
      '客户电话1: ',
      '客户电话2: '
    ];
    var content = [
      '白洁',
      '2019-10-24',
      '潜在',
      '2019年客户',
      '背景音乐',
      '自然客流',
      '高义',
      '13488998899',
      '13488998890',
      '白洁',
      '2019-10-24',
      '潜在',
      '2019年客户',
      '背景音乐',
      '自然客流',
      '高义',
      '13488998899',
      '13488998890'
    ];
    maps.clear();
    for (var i = 0; i < title.length; i++) {
      Map<String, dynamic> map = new Map();
      map['title'] = title[i];
      map['content'] = content[i];
      maps.add(map);
    }
  }

  Widget buildListItem(BuildContext context, Map<String, dynamic> map) {
    return Column(
      children: <Widget>[
//        Container(
//            child: SizedBox(
//          height: 100,
//          child: Swiper(
//            itemBuilder: (BuildContext context, int index) {
//              return images[index];
//            },
//            itemCount: 3,
//            itemWidth: 100,
//            itemHeight: 200,
//            pagination: SwiperPagination(
//                builder: DotSwiperPaginationBuilder(
//              color: Colors.black54,
//              activeColor: Colors.white,
//            )),
//            control: SwiperControl(),
//            scrollDirection: Axis.horizontal,
//            autoplay: true,
//            onTap: (index) => print('点击了第$index个'),
//          ),
//        )),
        Container(
          color: Colors.white,
          padding: EdgeInsets.all(15),
          child: Row(
            children: <Widget>[
              Text(
                map['title'],
                style: TextStyle(fontSize: 16, color: Colors.black87),
              ),
              SizedBox(
                width: 5,
              ),
              Text(
                map['content'],
                style: TextStyle(fontSize: 16, color: Colors.grey),
              ),
            ],
          ),
        ),
        Container(height: 1)
      ],
    );
  }
  List<Widget> images = [
    Image.network(
      "http://via.placeholder.com/350x150",
      fit: BoxFit.fill,
    ),
    Image.network(
      "http://via.placeholder.com/350x150",
      fit: BoxFit.fill,
    ),
    Image.network(
      "http://via.placeholder.com/350x150",
      fit: BoxFit.fill,
    ),
  ];
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          '客户详情',
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.grey[200],
        leading: IconButton(
            icon: Icon(
              Icons.arrow_back,
              color: Colors.black,
            ),
            onPressed: () {
              Navigator.pop(context);
            }),
        actions: <Widget>[
          IconButton(
              icon: Icon(
                Icons.edit,
                color: Colors.green,
              ),
              onPressed: () {
                String route = '${Routes.customeredit}';
                Routes.router.navigateTo(context, route,
                    replace: false, transition: TransitionType.fadeIn);
              }),
        ],
        elevation: 0.0,
      ),
      body: Container(
        color: Colors.grey[200],
        child: ListView(children: _doWidgets()),
      ),
    );
  }
}
